package com.yixun.quartz;

import com.alibaba.fastjson.JSONObject;
import com.yixun.component.RedisService;
import com.yixun.constant.SystemConstant;
import com.yixun.model.SiteIntroduction;
import com.yixun.service.ContinuousNullService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: yx
 * @Desc: 定时器-获取所有站点，分别分析站点是否连续20条数据为空
 * @Date: 11:33 2021/5/8
 **/
@Component
@Slf4j
public class ContinuousNullQuartz {

    @Autowired
    RedisService redisService;

    @Autowired
    ContinuousNullService continuousNullService;

    /**
     * 这里用定时器，用到多条数据就用redis
     * @Desc: 每过10分钟执行一次 从redis拉取20条数据    故障判断，判断站点是否有通道连续20条数据都为空
     **/
    //@Scheduled(cron = "0 0/10 * * * ?")
    @Scheduled(cron = "0 0/1 * * * ?")
    public void quartz(){
        //拉取所有站点
        String allSiteDeviceJson = redisService.get(SystemConstant.ALL_SITE_KEY);//all_site_device

        List<SiteIntroduction> siteIntroductions = JSONObject.parseArray(allSiteDeviceJson, SiteIntroduction.class);

        System.out.println("每过10分钟执行一次 ，先从redis获取所有站点55通道信息redis中拉取20条数据 ，故障判断，判断站点是否有通道连续20条数据都为空");
        if(siteIntroductions!=null)
        {
            //故障判断，判断站点是否有通道连续20条数据都为空
            continuousNullService.continuousNull(siteIntroductions);
        }


    }
}
